<template>
  <div class="page-containter">
    <uni-nav-bar fixed shadow :border="false" :title="'【练习】' + (detail && detail.name || '')" left-icon="left" @clickLeft="onClickLeft"></uni-nav-bar>
    <div class="page-content" v-if="detail">
      <div class="source fs-14 fc-fff ellipsis" v-if="detail.parentType">来源：{{detail.parentName}}</div>
      <div class="page-bg"
           :style="{
                background: 'url(' + detail.logoHttpUrl + ') center no-repeat'
            }" v-if="detail.logoHttpUrl"></div>
      <div class="page-bg" v-else></div>
      <div class="page-title fs-24 ellipsis2">{{detail.name}}</div>
      <div class="page-text fs-14">
        <span class="select-data" v-if="detail.status === '0' && detail.startDate">{{detail.startDate}} 开始</span>
        <span class="select-data" v-else-if="detail.status === '1' && detail.endDate">{{detail.endDate}} 结束</span>
        <span class="select-data" v-else-if="detail.status === '1'">结束时间无限制</span>
      </div>
      <div class="page-text fs-14" v-if="editionType === '2'">来自：{{detail.siteName}}</div>
      <div class="page-data">
        <div class="user-wrap">
          <div class="photo-wrap">
            <image :src="user && user.photoHttpUrl" v-if="user && user.photoHttpUrl" />
            <generatePhoto
                width="56px"
                :id="user && user.id || ''"
                :text="user && user.realName || ''"
                style="margin: 0 auto 0.16rem;"
                v-else></generatePhoto>
          </div>
          <div class="name-wrap fs-16 fc-333">{{user && user.realName || ''}}</div>
        </div>
        <div class="page-data-list flex-wrap flex-middle">
          <div class="page-data-item">
            <p class="fs-18 fc-333">{{detail.totalQuestionsNum || 0}}</p>
            <p class="fs-12 fc-999">试题数量</p>
          </div>
          <div class="page-data-item" @click="toNote(1)">
            <p class="fs-18 fc-333">{{detail.noteNum || 0}}</p>
            <p class="fs-12 fc-999">我的笔记</p>
          </div>
          <div class="page-data-item" @click="toNote(2)">
            <p class="fs-18 fc-333">{{detail.collectNum || 0}}</p>
            <p class="fs-12 fc-999">我的收藏</p>
          </div>
          <div class="page-data-item" @click="toNote(0)">
            <p class="fs-18 fc-333">{{detail.mistakesNum || 0}}</p>
            <p class="fs-12 fc-999">我的错题</p>
          </div>
        </div>
      </div>
      <div class="page-btn-title flex-wrap flex-middle">
        <div class="flex-item">
          <p class="fs-18 fc-333 fw-b">练习模块</p>
        </div>
      </div>
      <div class="page-btn flex-wrap">
        <div class="page-btn-left">
          <div class="page-btn-item page-btn-item-1" @click="toPage('1')">
            <div class="page-btn-1"></div>
            <p class="fs-14 fc-333 fw-b mt10">顺序练习</p>
          </div>
          <div class="page-btn-item flex-wrap flex-middle" @click="toPage('3')">
            <span class="page-btn-4"></span>
            <span class="fc-333">
                            <p class="fs-14 fc-333 fw-b">背题练习</p>
                        </span>
          </div>
        </div>
        <div class="page-btn-right">
          <div class="page-btn-item flex-wrap flex-middle" @click="toPage(0)">
            <span class="page-btn-2"></span>
            <span class="fs-14 fc-333 fw-b">题型练习</span>
          </div>
          <div class="page-btn-item flex-wrap flex-middle" @click="toPage('2')">
            <span class="page-btn-3"></span>
            <span class="fs-14 fc-333 fw-b">随机练习</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import generatePhoto from "@/components/dragMaker/generatePhoto"
import VanActionSheet from "@/components/vant/van-action-sheet/van-action-sheet.vue";
import practiceMock from "@/mock/practice/info.json"
export default {

  head() {
    return {
      title: this.detail && this.detail.name,
    }
  },
  data() {
    return {
      detail: null,
      id: '',
      listData: [],
      btnStatus: false,
      actionShow: false,
    }
  },
  components: {
    VanActionSheet,
    generatePhoto
  },
  onShow() {
    this.initPage()
  },
  methods: {
    onClickLeft() {
      uni.navigateBack({ delta: 1 })
    },

    initPage() {
      this.getInfo()
    },
    getInfo() {
		this.detail=practiceMock.data;
    },
    toPage(type) {
      let current = this.detail.completeStatusMap[type]
      if (this.detail.status !== "1") {
        this.$toast.warning(this.detail.status === '2' ? '当前练习已过期' : '当前练习未开始')
        return
      }
      if (type === 0) {
        this.$uniPush({
          name: "practice-type-id",
          params: {
            id: this.id
          }
        })
        return
      }
     this.handlePage(type, 2)
    },
    handlePage(type, iscontinue) {
      if (type === "4" && iscontinue === 2) {
        this.$uniPush({
          name: "practice-config-id",
          params: {
            id: this.id
          },
          query: {
            type: type,
            iscontinue: iscontinue
          }
        })
      } else if (type === "4") {
        this.$uniPush({
          name: "practice-exam-id",
          params: {
            id: this.id,
            iscontinue: iscontinue
          },
          query: {
            type: type
          }
        })
      } else {
        this.$uniPush({
          name: "practice-detail-id",
          params: {
            id: this.id,
            iscontinue: iscontinue
          },
          query: {
            type: type
          }
        })
      }
    },

    toNote(type) {
      this.$uniPush({
        name: "practice-note-detail",
        params: {
          type: type
        },
        query: {
          practiceId: this.id
        }
      })
    },

    toRanking(type) {
      this.$uniPush({
        name: "practice-ranking-id",
        params: {
          id: this.id
        }
      })
    },

    toDetail() {
      this.$uniPush({
        name: 'questionnaire-detail-id',
        params: {
          id: this.id
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.page-containter {
  background: #F5F8F8;
  padding-bottom: 15px;
  min-height: 100vh;
  .van-nav-bar{
    box-shadow: inset 0px -1px 0px 0px rgba(221,221,221,0.5);
  }
  .page-content{
    position: relative;
    padding: 0 15px;
    z-index: 2;
    .source {
      width: 345px;
      height: 32px;
      background: rgba(0,0,0,0.6);
      border-radius: 6px;
      text-align: center;
      position: absolute;
      line-height: 32px;
      top: 8px;
      left: 50%;
      transform: translate(-50%, 0);
      z-index: 5;
    }
    .page-bg{
      position: absolute;
      width: 100vw;
      height: 56.25vw;
      background: url(@/static/image/course-img.png) no-repeat;
      background-size: contain !important;
      z-index: -1;
      left: 0;
      top: 0;
      &:after{
        content: '';
        position: absolute;
        width: 100%;
        height: 100%;
        left: 0;
        top: 0;
        background: rgba(0, 0, 0, 0.3);
      }
    }
  }
  .page-title{
    position: relative;
    padding: 36px 0 0;
    line-height: 34px;
    color: #fff;
    text-align: center;
    z-index: 2;
    margin-bottom: 5px;
  }
  .page-text{
    position: relative;
    line-height: 20px;
    color: #fff;
    text-align: center;
    z-index: 2;
    & + .page-text{
      margin-top: 6px;
    }
  }
  .page-data{
    position: relative;
    height: 132px;
    background: #FFFFFF;
    border-radius: 6px;
    margin: 38px 0 0;
    .user-wrap{
      position: absolute;
      width: 100%;
      top: -30px;
      left: 0;
      .photo-wrap{
        width: 60px;
        height: 60px;
        border: 2px solid #FFFFFF;
        border-radius: 50%;
        overflow: hidden;
        background: #fff;
        margin: 0 auto 5px;
        img{
          width: 100%;
          height: 100%;
        }
        image{
          width: 100%;
          height: 100%;
        }
      }
      .name-wrap{
        font-weight: 500;
        line-height: 22px;
        text-align: center;
      }
    }
  }
  .select-data{
    & + .select-icon{
      &:before{
        content: "|";
        margin-right: 5px;
        margin-left: 1px;
      }
    }
  }
  .select-icon{
    color: #fff;
    &:after{
      border-left-color: #fff;
      border-bottom-color: #fff;
    }
  }
  .page-data-list{
    padding: 72px 4px 0;
    .page-data-item{
      flex: 1;
      text-align: center;
      .fs-18{
        margin-bottom: 2px;
      }
    }
  }

  .btn-wrap{
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    padding: 8px 15px;
    border-top: 1px solid #EEEEEE;
    background: #fff;
    z-index: 1000;
    button {
      width: 100%;
      height: 40px;
      &.btn-overdue{
        color: #666;
        background: #F5F5F5;
      }
    }
  }
  .page-btn-title{
    padding: 15px 0 10px;
    .flex-item{
      max-width: calc(100% - 74px);
    }
    .rank-wrap{
      width: 74px;
      height: 26px;
      background: #FCEFEF;
      border-radius: 16px;
      font-size: 12px;
      color: #E16565;
      .rank-icon{
        display: inline-block;
        width: 10px;
        height: 11px;
        background: url(@/static/image/practice-rank.png) no-repeat;
        background-size: cover;
        margin-right: 4px;
      }
    }
  }
  .page-btn{
    width: 100%;
    .page-btn-left,.page-btn-right{
      flex: 1
    }
    .page-btn-right{
      margin-left: 10px;
    }
    .page-btn-item{
      position: relative;
      padding: 18px 20px;
      background: #FFFFFF;
      border-radius: 6px;
      overflow: hidden;
      + .page-btn-item{
        margin-top: 10px;
      }
      &.page-btn-item-1{
        text-align: center;
        padding: 45px 20px 37px;
        background: url(@/static/image/practice-bg.png) no-repeat, #FFFFFF;
        background-size: 19px 22px;
        background-position: calc(50% + 27px) 27px;
      }
      .page-btn-1{
        width: 54px;
        height: 54px;
        background: url(@/static/image/practice-1.png) no-repeat;
        background-size: cover;
        margin: 0 auto;
      }
      .page-btn-2, .page-btn-3, .page-btn-4, .page-btn-5{
        width: 42px;
        height: 42px;
        margin-right: 10px;
        background-size: cover !important;
      }
      .page-btn-2{
        background: url(@/static/image/practice-2.png) no-repeat;
      }
      .page-btn-3{
        background: url(@/static/image/practice-3.png) no-repeat;
      }
      .page-btn-4{
        background: url(@/static/image/practice-4.png) no-repeat;
      }
      .page-btn-5{
        background: url(@/static/image/practice-5.png) no-repeat;
      }
      .page-btn-icon{
        position: absolute;
        width: 72px;
        height: 20px;
        background: var(--color);
        text-align: center;
        color: #fff;
        transform: rotate(45deg);
        right: -17px;
        top: 9px;
        line-height: 20px;
        font-size: 10px;
        &.icon-1{
          background: #4DAAFD;
        }
        &.icon-2{
          background: #D9635B;
        }
        &.icon-3{
          background: #FCBE26;
        }
        &.icon-4{
          background: #5434B7;
        }
        &.icon-5{
          background: #1EA69D;
        }
      }
    }
  }
  .van-popup{
    :deep(.van-action-sheet__header) {
      font-size: 18px;
      text-align: left;
      padding-left: 15px;
    }
    .action-content{
      font-size: 14px;
      padding: 15px;
      min-height: 20vh;
    }
  }
}
</style>
